home *** CD-ROM | disk | FTP | other *** search
/ 130 MIDI Tool Box / 130 MIDI Tool Box.iso / qb4midi / qbm-dem3.bas < prev    next >
BASIC Source File  |  1990-11-27  |  9KB  |  176 lines

  1.      '-------------------------------------------------------------------
  2.      '
  3.      '                     Q U I C K  B A S I C
  4.      '
  5.      '                   ███ ███ █████ ████  █████
  6.      '                   █ █ █ █   █   █   █   █
  7.      '                   █  █  █   █   █   █   █
  8.      '                   █  █  █ █████ ████  █████
  9.      '
  10.      '               QBMIDI(TM) Library Sample Programs
  11.      '
  12.      '                    Q B M - D E M 3 . B A S
  13.      '
  14.      '           S I M P L E   K E Y B O A R D   S P L I T
  15.      '
  16.      '          S H A R E W A R E    V E R S I O N    1 . 0
  17.      '
  18.      '                         Developed by:
  19.      '                 AskUs! Technology Specialists
  20.      '                          PO Box 737
  21.      '                    Bountiful, UT 84011-0737
  22.      '
  23.      '      QBMIDI is a trademark of AskUs! Technology Specialists
  24.      '              (c) 1990 AskUs! Technology Specialists
  25.      '-------------------------------------------------------------------
  26.  
  27.      DEFINT A-Z                                                  'Set all to integer
  28.     
  29.      CONST False = 0, True = NOT False                           'Set boolean constants
  30.  
  31.      CALL SeeIfMPUExists(Found)                                  'Stop if no
  32.      IF Found = 0 THEN PRINT "Midi Controller Missing": END      'MPU is found
  33.  
  34.      CALL ResetMpu                                               'Reset to power on status
  35.      CALL AllNotesOff                                            'Just in case
  36.      CALL SetDataInStopMode                                      'Turn off MPU intelligence
  37.      CALL OmniModeOn                                             'Set omni on - so all uses midi data
  38.  
  39.      CLS                                                         'Titles
  40.      PRINT "QBMIDI SIMPLE KEYBOARD SPLIT                               (c) 1990 AskUs!"
  41.      PRINT
  42.      PRINT "This will read the MIDI data coming in and select a datch number based on"
  43.      PRINT "where it is with regards to a split point you select.  Set the split location"
  44.      PRINT "you desire by pressing a key on your MIDI keyboard. We suggest starting with"
  45.      PRINT "middle C.  You can press Esc on the Computer keyboard to exit."
  46.      PRINT
  47.      PRINT "Press the key where a split will occur now ... ";
  48.      GOSUB SelectKeyForSplit
  49.      PRINT " Key"; SplitAtKeyNumber; "selected"
  50.      PRINT
  51.  
  52.      PRINT "Now select the patch (Voice) you'd like to use as the lower patch. You must"
  53.      PRINT "press the patch select on your keyboard ... ";
  54.      GOSUB SelectPatch: PatchOne = Patch
  55.      PRINT "Lower Patch will be"; PatchOne
  56.     
  57.      PRINT
  58.      PRINT "And select the patch to use as the upper patch.  Press the patch on your"
  59.      PRINT "keyboard ... ";
  60.      GOSUB SelectPatch: PatchTwo = Patch
  61.      PRINT "Upper Patch will be"; PatchTwo
  62.     
  63.      PRINT
  64.      PRINT
  65.      PRINT "Split established.  You may now play the keyboard or select new."
  66.      PRINT "Press Esc on the computer's keyboard to exit."
  67.   
  68.      'IMPORTANT NOTE:
  69.      'Some midi instruments save time by sending command changes only when
  70.      'the command changes to another type of command. For example, if playing
  71.      'a series of notes, MIDI might receive a 144 60 64 meaning 144 (command
  72.      'to turn note on), 60 (Note to play), and 64 (Velocity). A subsequent
  73.      'key pressed would send only two bytes - Note and Velocity.  Until you
  74.      'change the commands, like patch change, only two bytes will be sent.
  75.      'Your programs must be ready to receive these three and two byte
  76.      'commands and treat them accordingly.  The following uses flags as
  77.      'toggles to determine statuc of commands being received.
  78.  
  79.      DO
  80.           GOSUB WaitForMidiData                             'Wait for midi
  81.           IF Value > 127 THEN                               'If command then
  82.                NoteOnOff = False                            'Turn off flags
  83.                PatchChange = False
  84.                SELECT CASE Value                            'See what command
  85.                CASE IS = 144                                'was sent. If Note
  86.                     NoteOnOff = True                        'on/off then set
  87.                     GOSUB WaitForMidiData                   'flag, and get Note
  88.               
  89.                CASE IS = 192                                'If Patch change then
  90.                     GOSUB WaitForMidiData                   'Get patch number
  91.                     IF UsingPatchOne THEN                   'Depending on what
  92.                          PatchOne = Value                   'patch is active,
  93.                     ELSE                                    'change value to
  94.                          PatchTwo = Value                   'new patch selected
  95.                     END IF
  96.                END SELECT
  97.           END IF
  98.           IF NoteOnOff THEN                                 'If note was pressed
  99.                Note = Value                                 'Set note = to Value captured above
  100.                GOSUB WaitForMidiData: Velocity = Value      'Get the Velocity
  101.           END IF
  102.           IF OldNote THEN CALL PlayNote(OldNote, 0)         'Turn off old note
  103.           OldNote = Note                                    'Set old note to note
  104.          
  105.          
  106.           IF UsingPatchOne THEN                             'Based on patch
  107.                IF (Note <= SplitAtKeyNumber) THEN           'currently in use,
  108.                     CALL PlayNote(Note, Velocity)           'either play the
  109.                ELSE                                         'note or make a
  110.                     CALL ChangePatchTo(PatchTwo)            'Patch change and play
  111.                     UsingPatchOne = False                   'the note
  112.                     CALL PlayNote(Note, Velocity)
  113.                END IF
  114.          
  115.           ELSE                                              'Ditto, except Not
  116.                IF Note <= SplitAtKeyNumber THEN             'using PatchOne
  117.                     CALL ChangePatchTo(PatchOne)
  118.                     UsingPatchOne = True
  119.                     CALL PlayNote(Note, Velocity)
  120.                ELSE
  121.                     CALL PlayNote(Note, Velocity)
  122.                END IF
  123.           END IF
  124.      LOOP
  125.   
  126.  
  127. WaitForMidiData:                                            'Wait for any midi
  128.      DO                                                     'info
  129.           CALL ReceiveMidiData(Value)                       'Since ReceiveMidiData
  130.                                                             'returns -1 if idle, wait
  131.                                                             'for >-1 to exit loop
  132.           IF INKEY$ = CHR$(27) THEN GOTO Ending             'Unless they press ESC
  133.      LOOP UNTIL Value > True                                'Wait for Value >-1
  134.      RETURN
  135.  
  136.  
  137. SelectKeyForSplit:
  138.      DO                                                     'Wait for keypress
  139.           GOSUB WaitForMidiData                             'On MIDI keyboard
  140.           IF Value = 144 THEN
  141.                GOSUB WaitForMidiData
  142.                SplitAtKeyNumber = Value                     'and set split at
  143.           END IF                                            'the key pressed
  144.      LOOP UNTIL (SplitAtKeyNumber > 0)
  145.      RETURN
  146.  
  147. SelectPatch:                                                'Select patch. Note
  148.                                                             'that this will
  149.                                                             'catch accidental
  150.                                                             'keyboard presses
  151.                                                             'between time we
  152.                                                             'select first patch
  153.                                                             'and second
  154.      Patch = False
  155.      DO
  156.           GOSUB WaitForMidiData                             'Wait for midi
  157.           IF Value > 127 THEN                               'If command
  158.                IF Value <> 192 THEN                         'and not patch
  159.                     PatchSelect = False                     'set flag off
  160.                ELSE                                         'otherwise
  161.                     PatchSelect = True                      'set flag true
  162.                     GOSUB WaitForMidiData                   'and get patch value
  163.                END IF
  164.           END IF
  165.           IF PatchSelect = True THEN                        'If patch select
  166.                Patch = Value                                'then Value will be
  167.           END IF                                            'patch selected
  168.      LOOP UNTIL (Patch > 0)
  169.      RETURN
  170.  
  171.  
  172. Ending:
  173.      CALL AllNotesOff                                       'Don't leave any on
  174.      END
  175.  
  176.